#ifndef ABC_CONTAINER_H
#define ABC_CONTAINER_H
#include <memory>
#include <string>
#include <vector>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <functional>
#include "c/abckit.h"
#include <cstring>
#include "abc_commons.h"
#include "abckit_api/abckit_wrapper.h"

const auto abckitApi = createAbckitAdapter(abc::AbckitVersion::V1);

namespace abc
{

    class AbcArchive
    {
    public:
        using Ptr = std::shared_ptr<AbcArchive>;

        // 禁止拷贝
        AbcArchive(const AbcArchive &) = delete;
        AbcArchive &operator=(const AbcArchive &) = delete;

        const std::string &filePath() const noexcept { return filePath_; }
        const std::vector<AbcNodePtr> &nodes() const noexcept { return _nodes; }
        AbckitFile *file() const noexcept { return rawFile_; }

        // 查询接口
        // std::vector<AbcNodePtr> getNodes(AbcNodeType type) const;
        // std::vector<AbcFunctionPtr> getMethods() const;

        ~AbcArchive();

    private:
        explicit AbcArchive(const std::string &path) : filePath_(path) {};
        friend class AbcArchiveFactory;

        std::string filePath_;
        AbckitFile *rawFile_ = nullptr;
        std::vector<AbcNodePtr> _nodes; // 模块节点列表
    };

    class AbcArchiveFactory
    {
    public:
        static AbcArchive::Ptr create(const std::string &path);
        static void collectNode(AbcArchive *archive, CoreNode coreNode, AbcNodePtr parentNode);
        static void cleanNode(AbcArchive *archive);
        static void identifyFunctionType(AbcArchive *archive);
        static AbcFuncType identifyFunctionType(const abc::AbcFunctionPtr &function, bool isPage);
        static void scanFunctionsForLambdas(AbcArchive *archive);
    };
}; // namespace abc

#endif